package com.info.springmongo.exception;

import com.info.springmongo.common.ResultCode;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResultCode handleException(MethodArgumentNotValidException ex) {
        return ResultCode.fail(ex.getBindingResult().getFieldError().getDefaultMessage());
    }
}
